package com.yixun.qfbao.response.premises.detail;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.alibaba.fastjson.JSONArray;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author zilong.liu
 * @date 2020-8-12
 * 	佣金方案信息
 */
@Data
public class CommisionInfo implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@ApiModelProperty(value = "佣金方案名称")
	private String name;

	@ApiModelProperty(value = "佣金策略类型， 元  %")
	private String strategyType;
	
	private String strategyValue;
	
	
	@ApiModelProperty(value = "佣金描述")
	private String desc;
	
	
	
	/**
	 * 把数据库存储的json格式的佣金字符串转换为佣金集合
	 * @param commisionStr
	 */
	public static List<CommisionInfo> convertCommisionStrToList(String commisionStr) {
		if(StringUtils.isBlank(commisionStr)) {
			return null;
		}
		try {
			List<CommisionInfo> commisionInfos = new ArrayList<>();
			JSONArray jsonArray = JSONArray.parseArray(commisionStr);
			for (Object object : jsonArray) {
				@SuppressWarnings("unchecked")
				Map<String, Object> commisionMap = (Map<String, Object>) object;
				CommisionInfo commisionInfo = new CommisionInfo();
				commisionInfo.setDesc(String.valueOf(commisionMap.get("desc")));
				commisionInfo.setName(String.valueOf(commisionMap.get("name")));
				String type = String.valueOf(commisionMap.get("type"));
				String typeValue = String.valueOf(commisionMap.get("typeValue"));
				commisionInfo.setStrategyType(type);
				commisionInfo.setStrategyValue(typeValue);
				commisionInfos.add(commisionInfo);
			}
			return commisionInfos;
		} catch (Exception e) {
		}
		return null;
		
	}
}
